<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	template="/templates/modeloSistema.xhtml"
	xmlns:stella="http://stella.caelum.com.br/faces2">

	<ui:define name="menu">
		<ui:include src="/includes/menuPrincipal.xhtml" />
	</ui:define>

	<ui:define name="conteudo">

		<f:event listener="#{MBCargo.carregarCargos}" type="preRenderView" />

		<!-- Inicio do DataTable -->

		<h:form prependId="false" id="frmCarListagem">
			<p:dataTable id="tblCarListagem" widgetVar="tabelaCarListagem"
				value="#{MBCargo.cargos}" var="cargo"
				emptyMessage="Nenhum registro encontrado." paginator="true" rows="5"
				rowsPerPageTemplate="5,10,15,20"
				filteredValue="#{MBCargo.cargosFiltrados}">

				<f:facet name="header">
					<h:outputText value="Cargos Cadastrados" />
				</f:facet>

				<p:column headerText="Código" filterBy="#{cargo.codCargo}"
					sortBy="#{cargo.codCargo}">
					<h:outputText value="#{cargo.codCargo}" />
				</p:column>

				<p:column headerText="Nome" filterBy="#{cargo.nome}"
					sortBy="#{cargo.nome}">
					<h:outputText value="#{cargo.nome}" />
				</p:column>

				<p:column headerText="Descrição" filterBy="#{cargo.descricao}"
					sortBy="#{cargo.descricao}">
					<h:outputText value="#{cargo.descricao}" />
				</p:column>

				<p:column headerText="Inativo" >
					<h:outputText value="#{cargo.inativo}" />
				</p:column>



				<p:column headerText="Operações">
					<p:commandButton icon="ui-icon-trash" value="Excluir"
						oncomplete="PF('dlgCarExcluir').show();"
						update=":frmCarExcluir:pnlCarExcluir">
						<f:setPropertyActionListener value="#{cargo}"
							target="#{MBCargo.cargoDomain}" />

					</p:commandButton>

					<p:commandButton icon="ui-icon-pencil" value="Editar"
						oncomplete="PF('dlgCarAlterar').show();"
						update=":frmCarAlterar:pnlCarAlterar">
						<f:setPropertyActionListener value="#{cargo}"
							target="#{MBCargo.cargoDomain}" />
					</p:commandButton>
				</p:column>

				<f:facet name="footer">
					<p:commandButton value="Novo" oncomplete="PF('dlgCarNovo').show();"
						actionListener="#{MBCargo.prepararNovo}"
						update=":msgGlobal :frmCarNovo:pnlCarNovo" />
				</f:facet>
			</p:dataTable>
		</h:form>
		<!-- Fim do DataTable -->

		<!-- Inicio do Dialogo de Inclusão -->
		<p:dialog widgetVar="dlgCarNovo" closable="true" draggable="false"
			closeOnEscape="true" resizable="false" appendTo="@(body)"
			modal="true" header="Cadastrar Cargo">

			<h:form prependId="false" id="frmCarNovo">
				<h:panelGrid id="pnlCarNovo" columns="2">
					<p:outputLabel value="Nome: " for="nome2" />
					<p:inputText id="nome2" value="#{MBCargo.cargoDomain.nome}"
						maxlength="50" size="40" required="true"
						requiredMessage="Campo nome obrigatório" />

					<p:outputLabel value="Descrição: " for="desc" />
					<p:inputText id="desc" value="#{MBCargo.cargoDomain.descricao}"/>
				</h:panelGrid>

				<h:panelGrid columns="2">
					<p:commandButton value="Salvar"
						actionListener="#{MBCargo.incluirCargo}"
						update=":msgGlobal :frmCarListagem:tblCarListagem"
						oncomplete="verificar(xhr, status, args, 'dlgCarNovo', 'tabelaCarListagem')" />
					<p:commandButton value="Cancelar"
						onclick="PF('dlgCarNovo').hide();" process="@this">
						<p:resetInput target="pnlCarNovo" />
					</p:commandButton>
				</h:panelGrid>
			</h:form>
		</p:dialog>


		<!-- 		Final do Dialogo de inclusão -->

		<!-- 		Inicio o Dialogo de exclusão -->
		<p:dialog widgetVar="dlgCarExcluir" closable="true" draggable="false"
			closeOnEscape="true" resizable="false" appendTo="@(body)"
			modal="true" header="Excluir Cargo">

			<h:form prependId="false" id="frmCarExcluir">
				<h:panelGrid id="pnlCarExcluir" columns="2">

					<p:outputLabel value="Código: " />
					<h:outputText value="#{MBCargo.cargoDomain.codCargo}" />

					<p:outputLabel value="Nome: " />
					<h:outputText value="#{MBCargo.cargoDomain.nome}" />

					<p:outputLabel value="Descricao: " />
					<h:outputText value="#{MBCargo.cargoDomain.descricao}" />

				</h:panelGrid>

				<h:panelGrid columns="2">
					<p:commandButton value="Excluir"
						actionListener="#{MBCargo.excluirCargo}"
						update="@all"
						oncomplete="PF('dlgCarExcluir').hide();" />
					<p:commandButton value="Cancelar"
						oncomplete="PF('dlgCarExcluir').hide();" />
				</h:panelGrid>
			</h:form>
		</p:dialog>

		<!-- Final do Dialogo de Exclusão -->

		<!-- 		Inicio do Dialogo de Atualização -->

		<p:dialog widgetVar="dlgCarAlterar" closable="true" draggable="false"
			closeOnEscape="true" resizable="false" appendTo="@(body)"
			modal="true" header="Alterar Cargo">

			<h:form prependId="false" id="frmCarAlterar">
				<h:panelGrid id="pnlCarAlterar" columns="2">

					<p:outputLabel value="Código: " />
					<h:outputText value="#{MBCargo.cargoDomain.codCargo}" />

					<p:outputLabel for="nome1" value="Nome: " />
					<p:inputText id="nome1" value="#{MBCargo.cargoDomain.nome}"
						maxlength="50" size="40" required="true"
						requiredMessage="Campo nome obrigatório" />

					<p:outputLabel for="desc1" value="Descrição: " />
					<p:inputText id="desc1" value="#{MBCargo.cargoDomain.descricao}"
						 required="true"
						requiredMessage="Campo descrição obrigatório" />
				

					<p:outputLabel value="Inativo: " />
					<p:selectBooleanCheckbox value="#{MBCargo.cargoDomain.inativo}" />

				</h:panelGrid>

				<h:panelGrid columns="2">
					<p:commandButton value="Salvar"
						actionListener="#{MBCargo.alterarCargo}"
						update=":msgGlobal :frmCarListagem:tblCarListagem"
						oncomplete="verificar(xhr, status, args, 'dlgCarAlterar', 'tabelaCarListagem')" />
					<p:commandButton value="Cancelar"
						onclick="PF('dlgCarAlterar').hide();" process="@this">
						<p:resetInput target="pnlCarAlterar" />
					</p:commandButton>
				</h:panelGrid>
			</h:form>
		</p:dialog>

		<!-- 		Final do Dialogo de Atualização -->


	</ui:define>
</ui:composition>